package com.xyy.saas.payment.adpater.yzh.vo;

import com.xyy.saas.payment.adpater.yzh.constant.ConfigPath;
import com.xyy.saas.payment.util.ApolloUtil;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;

import java.io.Serializable;
import java.util.Date;

@Getter
@Setter
@ToString
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class NotifyResponse implements Serializable {

    private static final long serialVersionUID = -5499737776383286890L;
    /**
     * 时间戳，精确到秒
     **/
    private int timestamp = Integer.parseInt(String.valueOf(new Date().getTime()/1000));

    /**
     * 签名
     **/
    private String sign;

    /**
     * 签名方式，固定值rsa
     **/
    private String sign_type = "rsa";

    /**
     * 随机数，用于签名
     **/
    private String mess;

    /**
     * 经过加密后的具体数据
     **/
    private String data;

    // 获取加密明文
    public String getPlain(String method) {
        return new StringBuffer("data=")
                .append(data)
                .append("&mess=")
                .append(mess)
                .append("&timestamp=")
                .append(timestamp)
                .append("&key=")
                .append(ApolloUtil.getProperty(ConfigPath.HY_WX_PAY.equals(method) ?
                        ConfigPath.WX_YZH_APPKEY : ConfigPath.YZH_APPKEY))
                .toString();
    }

}
